package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.domain.Teacher;
/**
 * dao 库管,用于数据的增删改查
 */
public class  TeacherDao {
    private static Teacher[] tecs = new Teacher[5];

    public  Teacher[] findAllTeacher() {
        return tecs;
    }

    /**
     *添加学生
     * @param tec
     * @return
     */
    public boolean addTeacher(Teacher tec) {
        int index = -1;

        for (int i = 0; i < tecs.length; i++) {
            Teacher teacher = tecs[i];
            if(teacher == null){
                index = i;
                break;
            }
        }
        if (index == -1){
            //装满了
            return false;
        }else {
            //没装满.需要返回数组内容
            tecs[index] = tec;
            return true;
        }
    }

    /**
     * 删除学生方法
     * @param delId
     */
    public void deleteTeacherById(String delId) {
        //1.查找id所在索引位置
        int index = getIndex(delId);
        //2.将该索引位置使用null元素进行覆盖
        tecs[index] = null;

    }

    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < tecs.length; i++) {
            Teacher tec = tecs[i];
            index = i;
            break;
        }
        return index;
    }

    public void updateTeacher(String updateId, Teacher newtec) {
        //1.查找updateId,在容器中的位置
        int index = getIndex(updateId);
        //2.将索引位置,使用新的学生对象替换
        tecs[index] = newtec;
    }
}
